package com.cmsz.shuang.booter.web;

import com.cmsz.shuang.booter.dao.AccessMapper;
import com.cmsz.shuang.booter.dao.UserPoMapper;
import com.cmsz.shuang.booter.model.UserPo;
import com.vaadin.event.ShortcutAction;
import com.vaadin.spring.annotation.SpringComponent;
import com.vaadin.spring.annotation.UIScope;
import com.vaadin.ui.Button;
import com.vaadin.ui.CssLayout;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.ValoTheme;

@SpringComponent
@UIScope
public class UserEditor extends VerticalLayout {
	
	
	private AccessMapper accessMapper;
	
	private UserPoMapper userpoMapper;
	
	private UserPo userpo;
	
	TextField tfName= new TextField("Name");
	TextField tfPwd = new TextField("Password");
	
	Button save = new Button("Save");
	Button cancel = new Button("Cancel");
	Button delete = new Button("Delete");
	
	CssLayout actions = new CssLayout(save, cancel, delete);
	
	public UserEditor(){
		
		this.addComponents(tfName,  tfPwd, actions);
		setSpacing(true);
		actions.setStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
		save.setStyleName(ValoTheme.BUTTON_PRIMARY);
		save.setClickShortcut(ShortcutAction.KeyCode.ENTER);
		
		save.addClickListener(e -> { userpoMapper.insert(userpo) ;});
		delete.addClickListener( e -> { userpoMapper.deleteByPrimaryKey(userpo.getId() );});
		
		
		
		
		
	}
	
	
}
